import http from "./axios"
//获取新闻推荐列表
function getNewsId(id,number){
    let formUrl = new URLSearchParams()
    formUrl.append('pageNum','1')
    formUrl.append('pageSize',number)
    formUrl.append('categoryId',id)
    return http.post('/news-api/api/cms/article/open/list',formUrl)
}

function getNews(number){
    let formUrl = new URLSearchParams()
    formUrl.append('pageNum','1')
    formUrl.append('pageSize',number)
    return http.post('/news-api/api/cms/article/open/list',formUrl)
}
//获取新闻分类列表
function getNewsClassify(){
    let formUrl = new URLSearchParams()
    formUrl.append('pageSize','10')
    return http.post('/news-api/api/cms/category/open/list',formUrl)
}
//获取热门新闻分类列表
export function houtNews(pageNum){
    let formUrl = new URLSearchParams()
    formUrl.append('pageSize','10')
    formUrl.append('pageNum',pageNum)
    return http.post('/news-api/api/cms/article/open/hot/list',formUrl)
}
//搜索新闻
function searchNews(title,number){
    let formUrl = new URLSearchParams()
    formUrl.append('pageNum','1')
    formUrl.append('pageSize',number)
    formUrl.append('title',title)
    return http.post('/news-api/api/cms/article/open/list',formUrl)
}
//新闻详情
function articleDetails (articleId) {
    return http.get(' /news-api/api/cms/article/open/detail/' + articleId)
}

//上传图片
function uploadimg(file) {
    let form = new FormData()
    form.append("file",file)
    form.append("fileUseForEnum",'AVATAR')
    return http.post('/news-api/api/nos/upload/image',form)
}
//请求修改头像
function changeAvatar(file) {
    let form = new FormData()
    form.append("avatarfile",file)
    return http.post('/news-api/api/system/user/profile/update/avatar/nos',form)
}
//请求修改个人信息
function changeupdate(userName,sex,remark) {
    let form = new URLSearchParams()
    form.append("userName",userName)
    form.append("sex",sex)
    form.append("remark",remark)
    return http.post('/news-api/api/system/user/profile/update',form)
}
//新闻订阅
function journalismlist(id){
    let form = new URLSearchParams()
    form.append("categoryIds",id)
    return http.post('/news-api/api/cms/userCategory/subscription/category',form)
}
//已订阅列表
function subscriptionlist(){
    return http.get('/news-api/api/cms/category/subscription/list')
}
//******************************************************************

//收藏文章
export function collection (articleId) {
    return http.get('/news-api/api/cms/collect/collect/article/'+articleId)
}
//点赞文章
export function thumbsUp (articleId) {
    return http.get('/news-api/api/cms/article/add/zan/'+articleId)
}
//增加阅读量
export function thumbsUpLIst (articleId) {
    return http.get('/news-api/api/cms/article/open/add/read-num/'+articleId)
}
//收藏列表
export function conllectionList(){
    return http.get('/news-api/api/cms/article/collect/list')
}
//注册
export function registry(loginName,code,phonenumber,password,userName) {
    let urlParams = new URLSearchParams()
    urlParams.append("loginName",loginName)
    urlParams.append("code",code)
    urlParams.append("phonenumber",phonenumber)
    urlParams.append("userName",userName)
    urlParams.append("password",password)
    return http.post("/news-api/api/registry",urlParams)
}
//获取验证码
export function code(mobile) {
    return http.get('/news-api/api/short-message/vcode/'+mobile)
}
//忘记密码
export function forget(loginName,code,phonenumber,password) {
    let urlParams = new URLSearchParams()
    urlParams.append("loginName",loginName)
    urlParams.append("code",code)
    urlParams.append("phonenumber",phonenumber)
    urlParams.append("password",password)
    return http.post("/news-api/api/password/forget",urlParams)
}
//登录
export function login(username,password) {
    let urlParams = new URLSearchParams()
    urlParams.append("username",username)
    urlParams.append("password",password)
    urlParams.append("rememberMe",true)
    return http.post("/news-api/api/login",urlParams)
}
//退出登录
export function logout() {
    return http.get('/news-api/api/logout')
}
//获取轮播图
function getSlideshow(){
    let formUrl = new URLSearchParams()
    formUrl.append('pageNum','1')
    formUrl.append('pageSize','10')
    return http.post('/news-api/api/cms/article/open/banner/list',formUrl)
}
//获取个人信息
export function getUserInfo() {
    return http.get("/news-api/api/login-user/info")
}
//请求收藏列表
export function getSubscribe(){
    return http.get('/news-api/api/cms/article/collect/list')
}
//请求疫情接口
export function getYQ(k){
    return http.get('/yc-api/springTravel/risk?key='+k)
}
//请求热搜
function  getHotSearch () {
    return http.get('/song-api/music-api/search/hot')
}
//搜索音乐
function searchSong (keyword) {
    return http.get('/search-api/cloudsearch?keywords='+ keyword)
}
//获取音乐信息
function getMusic (id) {
    return http.get('/song-api/music-api/song/url/v1?id='+id)
}
//获取歌词
function getLyric (id) {
    return http.get('/song-api/music-api//lyric?id='+id)
}
//随机壁纸：https://api.apiopen.top/api/getImages?page=0&size=10
export function getWallpaper(){
    return http.get('https://api.apiopen.top/api/getImages?page=&size=10')
}
export {journalismlist,subscriptionlist,getNewsId,getNews,getNewsClassify,articleDetails,searchNews,getSlideshow,changeAvatar,uploadimg,changeupdate,searchSong,getMusic,getLyric,getHotSearch}

//星座
export function getConstellation(id){
    return http.get('https://api.vvhan.com/api/horoscope?type='+id+'&time=today')
}